package cn.com.oceansoft.osc.ms.schedule;

import cn.com.oceansoft.osc.ms.config.CallPoliceConfig;
import cn.com.oceansoft.osc.ms.domain.HzEntity;
import cn.com.oceansoft.osc.ms.persistence.IHzMapper;
import cn.com.oceansoft.osc.ms.schedule.entity.CallPoliceAlarm;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wuzy
 * @created 2017-08-07-10:20
 * @email wzy@oceansoft.com.cn
 */
//@Component
public class HzSchedule {

    @Resource
    IHzMapper hzMapper;

    @Scheduled(cron = "0/10 * * * * ? ")
    public void executeHzTask() throws Exception {
        List<HzEntity> hz= hzMapper.findHzBills();
        for (HzEntity item : hz) {
            JSONObject json = (JSONObject) JSON.parseObject(item.getJson_content());
            JSONArray files=(JSONArray)json.get("files");

            boolean isfind=true;
            for(int i=0;i<files.size();i++){
                JSONObject job = files.getJSONObject(i);
                String guid=job.getString("file_content");
                String url= hzMapper.getUrl(guid);
                if(StringUtils.isBlank(url))
                {
                    isfind=false;
                    break;
                }
                job.put("file_content", CallPoliceConfig.URL_ZHZX+url);
            }
            if(!isfind)
                continue;

            String content =JSONObject.toJSONString(json);
            hzMapper.updateHz(item.getGuid(),content);

        }



    }



}
